package com.safe.ocs.listeners;

import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.safe.ocs.services.readVocation;

public class readListener implements ServletContextListener{
	private Timer timer=null;

	@Override
	public void contextDestroyed(ServletContextEvent events) {
		timer.cancel();
		events.getServletContext().log("定时器销毁");
	}

	@Override
	public void contextInitialized(ServletContextEvent events) {
		 timer = new Timer(true);
		 events.getServletContext().log("定时器已启动");//添加日志，可在tomcat日志中查看到
		 System.out.println("定时器已启动");
		 timer.schedule(new readVocation(),0,15*1000);//调用定时任务，0表示任务无延迟，5*1000表示每隔5秒执行任务，60*60*1000表示一个小时。
		 events.getServletContext().log("已经添加任务");
	}

}
